package com.neusoft.util;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.neusoft.mapper.FoodMapper;
import com.neusoft.po.Food;

/**
 * @author chj
 * @date 2024年9月6日
 */
/**
 * 在静态工具类中注入mapper的方式示例
 */
@Component
public class Lock {

	@Autowired
	private FoodMapper foodMapper;

	private static Lock Lock;

	@PostConstruct
	public void init() {
		Lock = this;

		Lock.foodMapper = this.foodMapper;

	}

	public static boolean FoodCountLock(Integer foodCount) {
		// 验证食物数量小于对应ordersdetailet的quantity
		// 用于点餐进行食物增加的验证，并且在save时也进行验证
		return foodCount >= 0;
	}

	public static boolean FoodInfoLock(Food food) {
		// 用于修改食物信息时
		// 验证食物是否属于商家，不属于不能修改商品信息
		if (food == null) {
			return false;
		}
		int businessIdIn = food.getBusinessId();
		int foodId = food.getFoodId();
		int businessIdDB = Lock.foodMapper.getFoodById(foodId).getBusinessId();
		return businessIdIn == businessIdDB;
	}

	public static boolean EmptyLock(Integer num) {
		// 用于实现将密码单向加密后再存⼊数据库的功能。
		return num > 0;
	}
}
